﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OF.Web
{
    public partial class schools : System.Web.UI.Page
    {
        BLL.Addr.AreaCache area_cache = new BLL.Addr.AreaCache();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //省份列表
                rptProvince.DataSource = area_cache.GetAreaByPid(0);
                rptProvince.DataBind();
                string areaid = Request.QueryString["areaid"];
                if (!string.IsNullOrWhiteSpace(areaid))
                {
                    rptList.DataSource = area_cache.GetSchoolsByAreaId(Convert.ToInt32(areaid));
                    rptList.DataBind();
                }
            }
        }

        //二级城市
        protected void rptProvince_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Repeater rptCity = (Repeater)e.Item.FindControl("rptCity");
            //找到分类Repeater关联的数据项
            Model.Area model = (Model.Area)e.Item.DataItem;
            //城市列表
            rptCity.DataSource = area_cache.GetAreaByPid(model.id);
            rptCity.DataBind();
        }
        //三级区域
        protected void rptCity_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Repeater rptCountry = (Repeater)e.Item.FindControl("rptCountry");
            //找到分类Repeater关联的数据项
            Model.Area model = (Model.Area)e.Item.DataItem;
            //区域列表
            rptCountry.DataSource = area_cache.GetAreaByPid(model.id);
            rptCountry.DataBind();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            rptSchool.DataSource = area_cache.GetSchoolsByName(txtkey.Text);
            rptSchool.DataBind();
        }
    }
}